/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
// CEPoll_IOListener.h
//

#ifdef LINUX

#pragma once

#include "BaseDefine.h"
#include "Network_IOListener.h"
#include <Thread.h>
#include <Socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <fcntl.h>

/**
* @class CEPoll_IOListener
*  - 
*/
class NetworkSession;
class EPoll_IOListener : public Network_IOListener{
	enum{
		DEF_WAIT_EVENT_TIME=		-1,
	};

public:
	virtual bool initialize( unsigned int event_size, int port, int back_log );	
	virtual bool registerSession( NetworkSession* session );
	virtual bool unregisterSession( NetworkSession* session );	
	virtual int ioListener_process(){ return 0; }
	
	static bool availableThisListener();

	EPoll_IOListener();
	virtual ~EPoll_IOListener();

	virtual DEF_THREAD_RETURN run();

protected:		

private:
	int acceptSession();

	struct epoll_event* events_;
	int epoll_fd_;
	size_t event_size_;
	NetworkSession* listen_session_;
};

#endif
